package com.maochang.top.proxy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * 增强类
 */
@Component
@Aspect //作用是把当前类标识为一个切面供容器读取
@Order(1)
public class UserProxy {

    //前置通知
    @Before(value = "execution(* com.maochang.top.domian.User.add())")
    public void before() {
        System.out.println("前置增强--before......");
    }

    //后置通知（返回通知）
    @AfterReturning(value = "execution(* com.maochang.top.domian.User.add(..))")
    public void afterReturning() {
        System.out.println("后置增强-afterReturning.........");
    }

    //最终通知
    @After(value = "execution(* com.maochang.top.domian.User.add(..))")
    public void after() {
        System.out.println("最终通知-after......... finally错误后亦然执行");
    }

    //异常通知
    @AfterThrowing(value = "execution(* com.maochang.top.domian.User.add(..))")
    public void afterThrowing() {
        System.out.println("afterThrowing.........");
    }

    //环绕通知
    @Around(value = "execution(* com.maochang.top.domian.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前.........");
        //被增强的方法执行
        proceedingJoinPoint.proceed();
        System.out.println("环绕之后.........");
    }

}
